package com.etennis.controller;

import com.etennis.pojos.PageResult;
import com.etennis.pojos.ResponseResult;
import com.etennis.pojos.dto.web.GoodDTO;
import com.etennis.pojos.dto.web.GoodPageQueryDTO;
import com.etennis.pojos.entity.Commodity;
import com.etennis.pojos.vo.web.GoodVO;
import com.etennis.service.ICommodityService;
import com.etennis.service.IGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/web/good")
@Slf4j
@Api(tags = "网页端-商品管理接口")
@Validated
public class GoodController {
    @Autowired
    ICommodityService iCommodityService;


    @PostMapping("/save")
    @ApiOperation("新增商品")
    public ResponseResult save(@RequestBody GoodDTO goodDTO){
        iCommodityService.saveGood(goodDTO);
        return ResponseResult.okResult();
    }

    @PutMapping("/update")
    @ApiOperation("修改商品")
    public ResponseResult update(@RequestBody @Valid GoodDTO goodDTO){
        iCommodityService.updateGood(goodDTO);
        return ResponseResult.okResult();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询商品")
    public ResponseResult<PageResult<GoodVO>> page(GoodPageQueryDTO pageQueryDTO){
        PageResult<GoodVO> page=iCommodityService.pageGood(pageQueryDTO);
        return ResponseResult.okResult(page);
    }
}
